<template>
  <view>
    <view class="header">
      <view class="back" @click="back()">
        <uni-icons type="left" size="20" color="#fff"></uni-icons>
      </view>
      <text>搜索帖子</text>
    </view>
    <view class="input-box">
      <uni-search-bar @input="input" bgColor="#fff" :radius="100" cancelButton="none"
        placeholder="请输入搜索内容"></uni-search-bar>
    </view>

    <view class="goods-list">
      <block v-for='(item,index) in searchList' :key='index'>
        <interact-out :item='item' pid=1 @getInfo='getInfo()' @changeCollect="changeCollect($event)"
          @changeDianzan="changeDianzan($event)"></interact-out>
      </block>
    </view>
  </view>
  </view>
</template>

<script>
  import {
    mapState
  } from 'vuex'
  export default {
    data() {
      return {
        kw: '',
        timer: null,
        searchList: [],
      };
    },
    onShow() {},
    methods: {
      back() {
        uni.navigateBack()
      },
      input(e) {
        clearTimeout(this.timer)
        this.timer = setTimeout(() => {
          this.kw = e
          if (this.kw.trim() != '') this.getSearchList()
        }, 500)
      },
      async getSearchList() {
        const data = await uni.$http.post(`/users/post/search/page/${this.userInfo.studentId}/${this.kw}`, {
          page: 1,
          pagesize: 20
        })
        this.searchList = data.data.data.records
        console.log(data.data.data.records);
      },
    },
    computed: {
      ...mapState('my_user', ['userInfo']),
    }
  }
</script>

<style lang="scss">
  .header {
    position: relative;
    width: 100%;
    height: 140rpx;
    text-align: center;
    font-size: 36rpx;
    font-weight: 700;
    line-height: 170rpx;
    background-color: #b6edaa;
    color: #fff;

    .back {
      position: absolute;
      top: 4rpx;
      left: 23rpx;
      height: 50rpx;
    }
  }

  .input-box {
    background-color: #f5f5f5;
  }

  .goods-list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 20rpx;
  }
</style>